from datetime import timedelta
from airflow.operators.bash import BashOperator
from airflow.models import Variable
import pendulum

from spmi.dws.spmi.dws_piece_policy_summary_mt_sync import spmi_dws__dws_piece_policy_summary_mt_sync
from spmi.tidb.dws.tidb_dws_piece_policy_centerout_entry_summary_mt import tidb_dws_piece_policy_centerout_entry_summary_mt


# pro
tidb_host = Variable.get('bigdata_tidb_host')
tidb_port = Variable.get('bigdata_tidb_port')
tidb_url = Variable.get('bigdata_tidb_url_dws')
tidb_user = Variable.get('bigdata_tidb_user')
tidb_password = Variable.get('bigdata_tidb_password')

# uat tidb  uat-jms-tidb.yl.com 4001 yl_spmibill_report_rw  ZzA^G@4oJFCIjGbk
# tidb_host = "uat-jms-tidb.yl.com"
# tidb_port = 4001
# tidb_url = "jdbc:mysql://uat-jms-tidb.yl.com:4001/spmi_dm?useUnicode=true"
# tidb_user = "yl_spmibill_report_rw"
# tidb_password = "ZzA^G@4oJFCIjGbk"


# ############hive to tidb的信息############
# hive表默认分区表 分区为dt  如不是请跟进自己表进行调整sqoop命令
hive_table='spmi_tmp.dws_piece_policy_summary_mt_sync'
# tidb信息
tidb_table='spmi_dws.dws_piece_policy_centerout_generation_summary_mt'
# tidb是否是分区表 true ：tidb是分区表  false：tidb不是分区表
if_partitions='true'
partition_keys='d_type,fee_type'
partition_values='generation,BF012'
update_key='statistics_month,fee_type_code,send_agent_code,send_franchisee_code,send_network_code,piece_agent_code,customer_code,piece_franchisee_code,piece_network_code,sender_province_id,receiver_province_id,destination_code,weight_segment_sign'
# 每次推送天数
interval_dt=1
# 推送map个数（最大100map 一般20-50即可在15分钟内推送亿级别数据）
sqoop_maps=30



tidb_dws_piece_policy_centerout_generation_summary_mt = BashOperator(
    task_id='tidb_dws_piece_policy_centerout_generation_summary_mt',
    execution_timeout=timedelta(hours=1),
    email=['jarl.huang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    bash_command="spmi/tidb/dws/tidb_dws_piece_policy_centerout_generation_summary_mt/execute.sh",
    pool='spmi_piece',
    retries=0,
    pool_slots=1,
    params={'tidb_host':tidb_host,'tidb_port':tidb_port,'tidb_url':tidb_url,'tidb_user':tidb_user,'tidb_password':tidb_password,'hive_table':hive_table,'tidb_table':tidb_table,'if_partitions':if_partitions,'partition_keys':partition_keys,'partition_values':partition_values,'update_key':update_key,'interval_dt':interval_dt,'sqoop_maps':sqoop_maps}

)


tidb_dws_piece_policy_centerout_generation_summary_mt << [
    spmi_dws__dws_piece_policy_summary_mt_sync,
    tidb_dws_piece_policy_centerout_entry_summary_mt,

]